< previous page page_347 next page >

Page 347
has error handling set, and it immediately calls the Error2() procedure, which does not have any error handling. The Error2() procedure then calls the Error3() procedure, which also does not have any error handling. The Error3() procedure then performs a division by zero. When this happens, Visual Basic checks the call stack to find out where the last error trap was created. It will look back to the Error2() procedure and find out that theres no error trap in that procedure, so it then goes back to Error1(), where it will find an error trap. It then removes Error3() and Error2() from the call stack and calls the label in the Error1() procedure.
The Error1() procedure pops up a message box that says What happened?? It then performs a Resume Next. Where does this Resume Next go to? Does it go to the line after the line of code that generated the error in the Error3() procedure? No! It cant because Error3() is no longer is in memory. Therefore, the only place it can go to is the line after the call to the Error2() procedure within the Error1() procedure:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Sub Error1()
   On Error GoTo Error_EH

   Call Error2

   MsgBox "Calculation Complete?"

NormalExit:
   Exit Sub

Error_EH:
   MsgBox "What happened??"
   Resume Next
End Sub

Public Sub Error2()
   ' No error handling in here

   Call Error3

   ' The following line won't happen
   MsgBox "After the call to Error3"
End Sub

 
< previous page page_347 next page >

If you like this book, buy it!